package com.zsc.spring.study.regbean;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     * 实现ImportBeanDefinitionRegistrar，可以直接使用registry去注册bean
     * @param annotationMetadata
     * @param registry
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
        boolean contains1 = registry.containsBeanDefinition("com.rn.model.Blue");
        boolean contains2 = registry.containsBeanDefinition("com.rn.model.Red");
        if(contains1 && contains2){
            //注册bean的配置信息
            RootBeanDefinition beanDefinition = new RootBeanDefinition(Blue.class);
//			beanDefinition.
            //注册bean到容器中
            registry.registerBeanDefinition("rowRed", beanDefinition);
        }
    }
}
